package com.xcm.controller;

import com.xcm.model.JsonResponse;
import com.xcm.service.ProgramJsonService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/publish")
public class PublishController {
	private static Logger logger = LoggerFactory.getLogger(PublishController.class);
	@Autowired
	private ProgramJsonService programJsonService;
	/**
	 * 广告发布
	 */
	@ResponseBody
	@RequestMapping(value = "/update")
	public Object update(String version, String url) {
		//验证version
		if (StringUtils.isBlank(version)) {
			return new JsonResponse(1,"参数version不能为空");
		}
		//验证url
		if (StringUtils.isBlank(url)) {
			return new JsonResponse(2,"参数url不能为空");
		}
		try {
			programJsonService.publishProgram(version, url);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("PublishController update 广告发布失败：" + e.getMessage());
			return new JsonResponse(1,"广告发布失败");
		}
		return "";
	}


}
